#include <stdio.h>

#define MAXN 9

int gLen = 0;
void log(int L[], int len, const char* msg) {
    printf("\n %s L =", msg);
    for (int i = 0; i < len; i++ ) {
        printf("%d ", L[i]);
    }
    printf("\n");
}

void swap ( int L[], int i, int j ) {
    if (i  == j) return;
    int tmp = L[i];
    L[i] = L[j];
    L[j] = tmp;
}

void Permutation ( int L[], int Left, int Right ) {
    int i;
    if ( Left == Right ) {
        for ( i = 0; i <= Right; i++ ) printf("%d ",L[i]);
        printf("\n");
    } else {
        for ( i = Left; i <= Right; i++ ) {
            swap(L,Left,i);
            // log(L, gLen, " 111 ");
            Permutation(L,Left+1,Right);
            // log(L, gLen, " 222 ");
            swap(L,Left,i);
            // log(L, gLen, " 333 ");
        }
    }
}

int main () {
    int N, L[MAXN], i;
    scanf("%d",&N);
    // gLen = N;
    for ( i = 0; i < N; i++ ) L[i] = i + 1;
    Permutation(L,0,N-1);
    return 0;
}